import request from './request'

// 首页数据统计API
export const dashboardApi = {
  // 获取统计数据
  getDashboardStats() {
    return request({
      url: '/dashboard/stats',
      method: 'get'
    })
  },

  // 获取支付金额对比数据
  getPaymentComparison() {
    return request({
      url: '/dashboard/payment-comparison',
      method: 'get'
    })
  },

  // 获取用户统计
  getUserStats() {
    return request({
      url: '/dashboard/user-stats',
      method: 'get'
    })
  },

  // 获取订单统计
  getOrderStats() {
    return request({
      url: '/dashboard/order-stats',
      method: 'get'
    })
  }
}

// 模拟数据API（当后端接口不可用时的备用数据）
export const mockDashboardApi = {
  // 模拟获取统计数据
  getDashboardStats() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          msg: '获取成功',
          data: {
            visitors: 126560,
            visitorTrend: 12,
            paidUsers: 26560,
            paidUserTrend: 6,
            pageviews: 465600,
            pageviewTrend: 5,
            orders: 5600,
            orderTrend: 8,
            todayPayment: 610000,
            yesterdayPayment: 549000
          }
        })
      }, 500)
    })
  },

  // 模拟获取支付金额对比数据
  getPaymentComparison() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          msg: '获取成功',
          data: {
            today: 610000,
            yesterday: 549000,
            weekData: [
              { date: '周一', today: 580000, yesterday: 520000 },
              { date: '周二', today: 620000, yesterday: 580000 },
              { date: '周三', today: 590000, yesterday: 540000 },
              { date: '周四', today: 610000, yesterday: 560000 },
              { date: '周五', today: 650000, yesterday: 590000 },
              { date: '周六', today: 580000, yesterday: 520000 },
              { date: '周日', today: 610000, yesterday: 549000 }
            ]
          }
        })
      }, 300)
    })
  }
}
